node {
    gid = sh (script: "stat -c %g /run/containerd/containerd.sock", returnStdout: true,).trim()
    docker.withRegistry('https://im30cr.tencentcloudcr.com', 'im30cr') {

        stage('Preparation') {
            checkout scm
        }

        stage('Build') {
            timeout(40) {
                buildImage("im30cr.tencentcloudcr.com/im30/nodejs-beta:v${env.BUILD_NUMBER}",
                    "dockerfiles/nodejs/dockerfile.beta", "./dockerfiles/nodejs/")
            }
        }
        
    }
}

def buildImage(imageName, dockerfile, buildDir) {
    try {
        image = docker.build(imageName, "--force-rm -f ${dockerfile} ${buildDir}")
        image.push()
    } catch (err) {
        echo err.getMessage()
    }
    sh "docker rmi ${imageName}"
}